package com.chennan.algorithm.leetcode.six;

import org.apache.commons.lang3.StringUtils;

/**
 * @author chennan
 * @create 2022-06-01
 */
public class StrStr {
    public static int strStr(String haystack, String needle) {
        int nlength = needle.length();
        if(nlength==0){
            return 0;
        }
        int hlength = haystack.length();
        if(hlength < nlength){
            return -1;
        }
        char needLeFirst = needle.charAt(0);
        for (int i = 0; i< hlength - nlength+1; i++){
            if(haystack.charAt(i)==needLeFirst){
                if(haystack.substring(i,i+nlength).equals(needle)){
                    return i;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(strStr("a","a"));
    }
}
